import SwiftUI

struct VideoRow: View {
    let video: Video
    
    var body: some View {
        HStack {
            Image(systemName: video.thumbnail)
                .resizable()
                .scaledToFit()
                .frame(width: 120, height: 80)
                .background(Color.gray.opacity(0.3))
                .cornerRadius(8)
            
            VStack(alignment: .leading) {
                Text(video.title)
                    .font(.headline)
                    .lineLimit(2)
                Text(video.author)
                    .font(.subheadline)
                    .foregroundColor(.gray)
                Text("\(formattedDate(video.date)) • \(video.views.formattedNumber) views")
                    .font(.footnote)
                    .foregroundColor(.gray)
            }
            .padding(.leading, 8)
        }
        .padding(.vertical, 4)
    }
    
    private func formattedDate(_ date: Date) -> String {
        let formatter = DateFormatter()
        formatter.dateStyle = .medium
        return formatter.string(from: date)
    }
}

extension Int {
    var formattedNumber: String {
        if self >= 1_000_000 {
            return String(format: "%.1fM", Double(self) / 1_000_000)
        } else if self >= 1_000 {
            return String(format: "%.1fK", Double(self) / 1_000)
        } else {
            return "\(self)"
        }
    }
}


import SwiftUI

struct ContentView111: View {
    var body: some View {
        NavigationView {
            VStack {
                VideoRow(
                    video: Video(
                        title: "SwiftUI for Beginners",
                        author: "Apple Developer",
                        thumbnail: "video.fill",
                        date: Date(),
                        views: 1245
                    )
                )
                
                VideoRow(
                    video: Video(
                        title: "Understanding Swift",
                        author: "Coding with Chris",
                        thumbnail: "video.fill",
                        date: Date().addingTimeInterval(-86400),
                        views: 6890
                    )
                )
                
                VideoRow(
                    video: Video(
                        title: "Advanced SwiftUI Techniques",
                        author: "Ray Wenderlich",
                        thumbnail: "video.fill",
                        date: Date().addingTimeInterval(-604800),
                        views: 15234
                    )
                )
                VideoRow(
                    video: Video(
                        title: "Advanced SwiftUI Techniques",
                        author: "Ray Wenderlich",
                        thumbnail: "video.fill",
                        date: Date().addingTimeInterval(-604800),
                        views: 15234
                    )
                )
                VideoRow(
                    video: Video(
                        title: "Advanced SwiftUI Techniques",
                        author: "Ray Wenderlich",
                        thumbnail: "video.fill",
                        date: Date().addingTimeInterval(-604800),
                        views: 15234
                    )
                )
                VideoRow(
                    video: Video(
                        title: "Advanced SwiftUI Techniques",
                        author: "Ray Wenderlich",
                        thumbnail: "video.fill",
                        date: Date().addingTimeInterval(-604800),
                        views: 15234
                    )
                )
                VideoRow(
                    video: Video(
                        title: "Advanced SwiftUI Techniques",
                        author: "Ray Wenderlich",
                        thumbnail: "video.fill",
                        date: Date().addingTimeInterval(-604800),
                        views: 15234
                    )
                )
                VideoRow(
                    video: Video(
                        title: "Advanced SwiftUI Techniques",
                        author: "Ray Wenderlich",
                        thumbnail: "video.fill",
                        date: Date().addingTimeInterval(-604800),
                        views: 15234
                    )
                )
                VideoRow(
                    video: Video(
                        title: "Advanced SwiftUI Techniques",
                        author: "Ray Wenderlich",
                        thumbnail: "video.fill",
                        date: Date().addingTimeInterval(-604800),
                        views: 15234
                    )
                )
                VideoRow(
                    video: Video(
                        title: "Advanced SwiftUI Techniques",
                        author: "Ray Wenderlich",
                        thumbnail: "video.fill",
                        date: Date().addingTimeInterval(-604800),
                        views: 15234
                    )
                )
                VideoRow(
                    video: Video(
                        title: "Advanced SwiftUI Techniques",
                        author: "Ray Wenderlich",
                        thumbnail: "video.fill",
                        date: Date().addingTimeInterval(-604800),
                        views: 15234
                    )
                )
                VideoRow(
                    video: Video(
                        title: "Advanced SwiftUI Techniques",
                        author: "Ray Wenderlich",
                        thumbnail: "video.fill",
                        date: Date().addingTimeInterval(-604800),
                        views: 15234
                    )
                )
                VideoRow(
                    video: Video(
                        title: "Advanced SwiftUI Techniques",
                        author: "Ray Wenderlich",
                        thumbnail: "video.fill",
                        date: Date().addingTimeInterval(-604800),
                        views: 15234
                    )
                )
                VideoRow(
                    video: Video(
                        title: "Advanced SwiftUI Techniques",
                        author: "Ray Wenderlich",
                        thumbnail: "video.fill",
                        date: Date().addingTimeInterval(-604800),
                        views: 15234
                    )
                )
                VideoRow(
                    video: Video(
                        title: "Advanced SwiftUI Techniques",
                        author: "Ray Wenderlich",
                        thumbnail: "video.fill",
                        date: Date().addingTimeInterval(-604800),
                        views: 15234
                    )
                )
                VideoRow(
                    video: Video(
                        title: "Advanced SwiftUI Techniques",
                        author: "Ray Wenderlich",
                        thumbnail: "video.fill",
                        date: Date().addingTimeInterval(-604800),
                        views: 15234
                    )
                )
            }
            .navigationTitle("YouTube")
        }
    }
}

